"use strict";

const Service = require("egg").Service;

class GoodsService extends Service {
  //列表查看
  async goodsList(pageIndex, pageSize) {
    // console.log(user);
    const res = await this.app.mysql.select("goods", {
      // 搜索 post 表
      limit: pageIndex * pageSize, // 返回数据量
      offset: (pageIndex - 1) * pageSize, //数据偏移量
    });
    const total = await this.app.mysql.select("goods");
    return { total, res };
  }
  // 添加
  async goodsAdd(name) {
    const { app } = this;
    await app.mysql.insert("goods", { name: name });
    return true;
  }
  // 删除
  async goodsDel(id) {
    const { app } = this;
    await app.mysql.delete("goods", {
      id: id,
    });
    return true;
  }
  // 编辑
  async goodsSet(id, name) {
    const { app } = this;
    await app.mysql.update("goods", {
      id: id,
      name: name,
    });
    return true;
  }
}
module.exports = GoodsService;
